"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "CasContext", {
  enumerable: true,
  get: function get() {
    return _CasContext.default;
  }
});
Object.defineProperty(exports, "CasWrapper", {
  enumerable: true,
  get: function get() {
    return _wrapper.default;
  }
});
Object.defineProperty(exports, "authorized", {
  enumerable: true,
  get: function get() {
    return _Authorized.default;
  }
});
Object.defineProperty(exports, "casConfig", {
  enumerable: true,
  get: function get() {
    return _config.casConfig;
  }
});
Object.defineProperty(exports, "check", {
  enumerable: true,
  get: function get() {
    return _check.default;
  }
});
Object.defineProperty(exports, "checkCookieTicket", {
  enumerable: true,
  get: function get() {
    return _check.checkCookieTicket;
  }
});
Object.defineProperty(exports, "checkTicket", {
  enumerable: true,
  get: function get() {
    return _check.checkTicket;
  }
});
Object.defineProperty(exports, "checkUrlTicket", {
  enumerable: true,
  get: function get() {
    return _check.checkUrlTicket;
  }
});
Object.defineProperty(exports, "cookie", {
  enumerable: true,
  get: function get() {
    return _casCookie.cookie;
  }
});
Object.defineProperty(exports, "event", {
  enumerable: true,
  get: function get() {
    return _events.default;
  }
});
exports.getHost = getHost;
Object.defineProperty(exports, "getParams", {
  enumerable: true,
  get: function get() {
    return _params.getParams;
  }
});
exports.initCas = initCas;
exports.login = login;
exports.logout = logout;
Object.defineProperty(exports, "setConfig", {
  enumerable: true,
  get: function get() {
    return _config.default;
  }
});
Object.defineProperty(exports, "setParams", {
  enumerable: true,
  get: function get() {
    return _params.setParams;
  }
});
exports.soc = soc;

var _config = _interopRequireWildcard(require("./config"));

var _check = _interopRequireWildcard(require("./check"));

var _casCookie = _interopRequireWildcard(require("@yjtec/cas-cookie"));

var _Authorized = _interopRequireDefault(require("./Authorized/"));

var _events = _interopRequireDefault(require("./events"));

var _CasContext = _interopRequireDefault(require("./CasContext"));

var _config2 = _interopRequireDefault(require("./config/config.js"));

var _redirect = _interopRequireDefault(require("./redirect"));

var _params = require("./params.js");

var _wrapper = _interopRequireDefault(require("./wrapper"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function initCas(opt) {
  //初始化config
  (0, _config.default)(_objectSpread(_objectSpread({}, _config2.default), opt)); //初始化cookie

  var _casConfig$get = _config.casConfig.get('cookie.path', '/'),
      cookieOpt = _casConfig$get.cookieOpt;

  var type = _config.casConfig.get('type');

  (0, _casCookie.default)(_config.casConfig.get('type', 'default'), _config.casConfig.get('cookie.path', '/'), _config.casConfig.get('cookie.domain', null));
}

function login() {
  var uri = getHost();
  var defaultUri = _config.casConfig.get('type') + '/login';
  uri += '/' + _config.casConfig.get('uri.login', defaultUri) + '?redirect=' + (0, _redirect.default)();
  window.location.href = uri;
}

function logout() {
  var uri = getHost();
  var defaultUri = _config.casConfig.get('type') + '/logout';
  uri += '/' + _config.casConfig.get('uri.logout', defaultUri) + '?redirect=' + (0, _redirect.default)();

  _events.default.emit('cas.logout', {
    uri: uri
  });
}

function soc(platfrom, callback) {
  if (platfrom === 'wx') {
    platfrom = 'wechat';
  }

  var uri = getHost();
  uri += '/soc/' + _config.casConfig.get('type', 'default') + '/' + platfrom;

  if (callback) {
    //singlegetuser只获取第三方用户信息，返回soc，不直接跳转登录
    uri += '?singlegetuser=true&callback=' + callback;
  }

  window.location.href = uri;
}

function getHost() {
  return _config.casConfig.get('host', '/');
}